using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Dracham.GUI.Controls
{
    internal static class Controls
    {
        private static List<Control> controls = new List<Control>();
        private static Control focusedControl;
        public static void Add(Control c)
        {
            controls.Add(c);
        }

        public static void Update(GameTime gt)
        {
            MouseState mState = Mouse.GetState();
            KeyboardState kState = Keyboard.GetState();

            //
            // check for focus change
            if (mState.LeftButton == ButtonState.Pressed)
            {
                focusedControl = null;
                foreach (Control c in controls)
                {
                    if (mState.X > c.Location.X && mState.X < (c.Location.X + c.Size.Width) && mState.Y > c.Location.Y && mState.Y < (c.Location.Y + c.Size.Height))
                    {
                        focusedControl = c;
                        focusedControl.Focused = true;
                        break;
                    }
                    else { c.Focused = false; }
                }
            }

            if (focusedControl != null)
            {
                focusedControl.Update(gt, mState, kState);
            }
        }
    }
}
